package com.geese.module.security.service;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.geese.common.entity.Permission;
import com.geese.module.security.dao.PermissionMapper;
import com.geese.module.security.dao.RolePermissionMapper;
import com.google.common.collect.Lists;

@Service
public class PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Autowired
    private RolePermissionMapper rolePermissionMapper;
    
    public List<Permission> listByRoleIds(List<Integer> roleIds) {
    	if(CollectionUtils.isEmpty(roleIds)) {
    		return Lists.newArrayList();
    	}
    	List<Integer> permissionIds = rolePermissionMapper.listByRoleIds(roleIds);
    	if(CollectionUtils.isEmpty(permissionIds)) {
    		return Lists.newArrayList();
    	}
		return permissionMapper.listByIds(permissionIds);
	}

    /**
     * 获取全部资源列表
     */
	public List<Permission> listAll() {
		return permissionMapper.listAll();
	}
    
//
//    public List<Permission> findAllChildPermission() {
//        return permissionMapper.findByPidGreateThan(0);
//    }
//
//    public List<Permission> findByPid(Integer pid) {
//        return permissionMapper.findByPid(pid);
//    }
//
//    public List<Permission> findByUserId(Integer userId) {
//        return permissionMapper.findByUserId(userId);
//    }
//
//    public boolean save(Permission permission) {
//        return permissionMapper.insert(permission);
//    }
//
//    public boolean edit(Permission permission) {
//        return permissionMapper.updateByPrimaryKeySelective(permission);
//    }
//
//    public void delete(int id) {
//        Permission permission = permissionMapper.selectByPrimaryKey(id);
//        if (permission != null) {
//            if (permission.getPid() == 0) {
//                permissionMapper.deleteByPid(permission.getPid());
//            }
//            permissionMapper.deleteByPrimaryKey(id);
//            rolePermissionMapper.deleteByPerId(id);
//        }
//    }
}
